package com.jingdianjichi.practice.server.rpc;

import com.jingdianjichi.auth.api.UserFeignService;
import com.jingdianjichi.auth.entity.AuthUserDTO;
import com.jingdianjichi.auth.entity.Result;
import com.jingdianjichi.practice.server.entity.dto.UserInfo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 远程调用auth服务
 */
@Component
public class UserRpc {

    @Resource
    private UserFeignService userFeignService;

    //封装用户信息
    public UserInfo getUserInfo(String userName) {
        AuthUserDTO authUserDTO = new AuthUserDTO();
        authUserDTO.setUserName(userName);

        Result<AuthUserDTO> result = userFeignService.getUserInfo(authUserDTO);

        UserInfo userInfo = new UserInfo();

        if (!result.getSuccess()) {
            return userInfo;
        }

        AuthUserDTO data = result.getData();
        userInfo.setUserName(data.getUserName());
        userInfo.setNickName(data.getNickName());
        userInfo.setAvatar(data.getAvatar());

        return userInfo;
    }

}
